package com.tz.service;

import com.tz.dao.ProductDao;
import com.tz.entity.Category;
import com.tz.entity.Commodity;
import com.tz.entity.Page;
import com.tz.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 16-7-20.
 */
//@Component
public class ProductServiceMockImpl implements ProductService {

   // @Autowired
    private ProductDao productDao;

    @Override
    public Page<Product> search(String categoryId,
                                int pageNumber,
                                String sortBy,
                                String sortOrder,
                                String viewType) {

        Page<Product> page = new Page<Product>();
        if(pageNumber==0){
            page.setPageNumber(1);
        }else{
            page.setPageNumber(pageNumber);
        }
        page.setTotalCount(18);
        //根据 视图类型 6,9
        if ("LIST".equals(viewType)) {
            page.setData(getMockPorudt(6));
            page.setTotalPage(3);
            page.setPageSize(6);
        } else {
            page.setData(getMockPorudt(9));
            page.setTotalPage(2);
            page.setPageSize(9);
        }

        return page;
    }

/*    @Override
    public Product findProductByProductId(long productId) {
        Product p = new Product();
        Category c = new Category();
        c.setId(1);
        p.setName("Test Product " + productId);
        p.setPrice(100.00 + productId);
        p.setId(productId);
        p.setCategory(c);
        return p;
    }

    @Override
    public List<Product> findProductByCategoryId(long categoryId) {
        return getMockPorudt(6);
    }

    @Override
    public void saveCommodity(Commodity commodity) {

    }

    @Override
    public void test() {
        System.out.println("productService.test() run...");
    }*/

    /**
     * 产生hardcode产品数据
     */
    private List<Product> getMockPorudt(int total) {
        List<Product> list = new ArrayList();
        for (int i = 0; i < total; i++) {
            Product p = new Product();
            Category c = new Category();
            c.setId(1);
            p.setName("Test Product " + i);
            p.setPrice(100.00 + i);
            p.setCategory(c);
            list.add(p);
        }
        return list;
    }
}
